package com.appwoo.txtws.service;

import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import com.appwoo.txtws.component.Global;
import com.appwoo.txtws.component.Logger;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class FileService
{
  private static String SERVICE_URL_LOGIN = Global.FileURL;

  private byte[] Bitmap2Bytes(Bitmap paramBitmap)
  {
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    paramBitmap.compress(Bitmap.CompressFormat.PNG, 100, localByteArrayOutputStream);
    return localByteArrayOutputStream.toByteArray();
  }

  private Bitmap drawableToBitmap(Drawable paramDrawable)
  {
    int i = paramDrawable.getIntrinsicWidth();
    int j = paramDrawable.getIntrinsicHeight();
    if (paramDrawable.getOpacity() != -1);
    for (Bitmap.Config localConfig = Bitmap.Config.ARGB_8888; ; localConfig = Bitmap.Config.RGB_565)
    {
      Bitmap localBitmap = Bitmap.createBitmap(i, j, localConfig);
      Canvas localCanvas = new Canvas(localBitmap);
      paramDrawable.setBounds(0, 0, paramDrawable.getIntrinsicWidth(), paramDrawable.getIntrinsicHeight());
      paramDrawable.draw(localCanvas);
      return localBitmap;
    }
  }

  public void uploadFile(String paramString1, String paramString2, String paramString3)
  {
    while (true)
    {
      StringBuffer localStringBuffer;
      int j;
      try
      {
        HttpURLConnection localHttpURLConnection = (HttpURLConnection)new URL(SERVICE_URL_LOGIN).openConnection();
        localHttpURLConnection.setDoInput(true);
        localHttpURLConnection.setDoOutput(true);
        localHttpURLConnection.setUseCaches(false);
        localHttpURLConnection.setRequestMethod("POST");
        localHttpURLConnection.setRequestProperty("Connection", "Keep-Alive");
        localHttpURLConnection.setRequestProperty("Charset", "UTF-8");
        localHttpURLConnection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + "*****");
        DataOutputStream localDataOutputStream = new DataOutputStream(localHttpURLConnection.getOutputStream());
        localDataOutputStream.writeBytes("--" + "*****" + "\r\n");
        localDataOutputStream.writeBytes("Content-Disposition: form-data; name=\"file1\";filename=\"" + paramString3 + "@" + paramString2 + "\"" + "\r\n");
        localDataOutputStream.writeBytes("\r\n");
        FileInputStream localFileInputStream = new FileInputStream(paramString1);
        byte[] arrayOfByte = new byte[1024];
        int i = localFileInputStream.read(arrayOfByte);
        if (i == -1)
        {
          localDataOutputStream.writeBytes("\r\n");
          localDataOutputStream.writeBytes("--" + "*****" + "--" + "\r\n");
          localFileInputStream.close();
          localDataOutputStream.flush();
          InputStream localInputStream = localHttpURLConnection.getInputStream();
          localStringBuffer = new StringBuffer();
          j = localInputStream.read();
          if (j == -1)
            localDataOutputStream.close();
        }
        else
        {
          localDataOutputStream.write(arrayOfByte, 0, i);
          continue;
        }
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
        return;
      }
      char c = (char)j;
      localStringBuffer.append(c);
    }
  }

  public boolean uploadIcon(Drawable paramDrawable, String paramString1, String paramString2)
  {
    StringBuffer localStringBuffer;
    try
    {
      URL localURL = new URL(SERVICE_URL_LOGIN);
      byte[] arrayOfByte = Bitmap2Bytes(drawableToBitmap(paramDrawable));
      HttpURLConnection localHttpURLConnection = (HttpURLConnection)localURL.openConnection();
      localHttpURLConnection.setDoInput(true);
      localHttpURLConnection.setDoOutput(true);
      localHttpURLConnection.setUseCaches(false);
      localHttpURLConnection.setRequestMethod("POST");
      localHttpURLConnection.setRequestProperty("Connection", "Keep-Alive");
      localHttpURLConnection.setRequestProperty("Charset", "UTF-8");
      localHttpURLConnection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + "*****");
      DataOutputStream localDataOutputStream = new DataOutputStream(localHttpURLConnection.getOutputStream());
      localDataOutputStream.writeBytes("--" + "*****" + "\r\n");
      localDataOutputStream.writeBytes("Content-Disposition: form-data; name=\"file1\";filename=\"" + paramString2 + "@" + paramString1 + "\"" + "\r\n");
      localDataOutputStream.writeBytes("\r\n");
      localDataOutputStream.write(arrayOfByte, 0, arrayOfByte.length);
      localDataOutputStream.writeBytes("\r\n");
      localDataOutputStream.writeBytes("--" + "*****" + "--" + "\r\n");
      localDataOutputStream.flush();
      InputStream localInputStream = localHttpURLConnection.getInputStream();
      localStringBuffer = new StringBuffer();
      while (true)
      {
        int i = localInputStream.read();
        if (i == -1)
        {
          localDataOutputStream.close();
          if (!"ok".equals(localStringBuffer.toString()))
            break;
          Logger.v("uploadIcon", paramString1 + ":" + localStringBuffer.toString());
          return true;
        }
        localStringBuffer.append((char)i);
      }
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
    while (true)
    {
      return false;
      Logger.v("uploadIcon", paramString1 + ":" + localStringBuffer.toString());
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.service.FileService
 * JD-Core Version:    0.6.2
 */